﻿using Microsoft.AspNetCore.Components.Forms;

namespace BlazorCountdown.Pages;
partial class Index
{
    MobileViewModel Model { get; set; } = new();

    EditContext Context { get; set; }

    string? Error { get; set; }

    protected override void OnInitialized()
    {
        Context = new(Model);
    }

    int Countdown = 10;
    bool StartCountdown = false;

    Timer _timer;
    Task GetCode()
    {
        StartCountdown = true;


        _timer = new(state =>
        {
            Countdown--;
            if (Countdown <= 0)
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                StartCountdown = false;
                Countdown = 10;
            }
            InvokeAsync(StateHasChanged);
        }, null, 0, 1000);

        return Task.CompletedTask;
    }

}


class MobileViewModel
{
    public string Mobile { get; set; }
    
    public string Code { get; set; }
}